home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / jaz_clib.arc / JZRPLSTR.C < prev    next >
Text File  |  1989-04-09  |  2KB  |  50 lines

  1. /*
  2. ┌────────────────────────────────────────────────────────────────────────────┐
  3. │jzrplstr.c                                     │
  4. │Replace characters in a string.                         │
  5. │Notes, no check is done for the length exceeding the sizeof(fdestin) so     │
  6. │you must be sure to allow enough space.                     │
  7. │                                         │
  8. │synopsis:                                     │
  9. │   char *s="this is a test";                                                │
  10. │   jzrplstr(s,"THIS",0,4);                                                  │
  11. │   { becomes "THIS is a test" }                                             │
  12. │                                         │
  13. │ (c) JazSoft 1986 by Jack A. Zucker @301-794-5950 | CIS:75766,1336         │
  14. └────────────────────────────────────────────────────────────────────────────┘
  15. */
  16.  
  17. #include <jaz.h>
  18. jzrplstr(fdestin,fsource,fstart,fnum)
  19. char *fdestin;        /* source string */
  20. char *fsource;        /* destination string */
  21. int fstart;        /* starting index */
  22. int fnum;        /* number of chars to replace */
  23. {
  24.  
  25.   int wslen,wdlen;        /* source and destination length */
  26.   int wpos,w;
  27.  
  28.   wslen = strlen(fsource);    /* length of source */
  29.   wdlen = strlen(fdestin);    /* length of destin */
  30.  
  31.   fnum = min(wslen,fnum);    /* don't put more chars then we have */
  32.  
  33.   wpos    = min(fstart,wdlen);    /* don't go beyond end of string */
  34.  
  35.   fdestin += wpos;        /* point to starting position */
  36.  
  37.   while (wpos < fstart) {    /* check for start pos > than destin string */
  38.     *fdestin++ = ' ';           /* pad with blanks */
  39.     fstart --;
  40.   }
  41.  
  42.   for (w = 0 ; w < fnum ; w++)    /* insert the string */
  43.     *fdestin++ = *fsource ++;
  44.  
  45.                 /* did we pad with blanks earlier? */
  46.   if (wpos + fnum >= wdlen) *fdestin = 0;
  47.  
  48. }
  49.  
  50.